package com.logic.modular.act.cultivate;

import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.modular.act.cultivate.vo.CultivateVo;
import com.logic.modular.game.player.science.PlayerScienceService;
import com.logic.modular.gameCore.cultivate.science.service.CoreSciencePropConfigServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags = "养成-科技")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/playerScienceAct")
public class PlayerScienceAction {
    @Resource
    private PlayerScienceService playerScienceService;

    @ApiOperation("科技商店")
    @PostMapping("/obtainShop")
    public ResponseResult<?> obtainShop() {
        return ResponseResult.success(CoreSciencePropConfigServiceImpl.listCache());
    }

    @ApiOperation("每打开科技面板调用一次")
    @PostMapping("/refreshCD")
    public ResponseResult<?> refreshCD(
            @RequestHeader String token
    ) {
        return ResponseResult.success(playerScienceService.refreshCD(JwtUtils.getPlayerId(token)));
    }

    @ApiOperation("购买计策")
    @PostMapping("/pay")
    public ResponseResult<?> pay(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerScienceVo.pay pram
    ) {
        return ResponseResult.success(playerScienceService.pay(JwtUtils.getPlayerId(token), pram.getSciencePropId()));
    }

    @ApiOperation("科技加速")
    @PostMapping("/accelerate")
    public ResponseResult<?> accelerate(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerScienceVo.accelerate pram
    ) {
        return ResponseResult.success(playerScienceService.accelerate(JwtUtils.getPlayerId(token), pram.getNum()));
    }
}
